<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="custom" tagdir="/WEB-INF/tags" %>
<html>
<body>
<form:form commandName="formDto" id="changeCategoryForm">
    <form:hidden path="uuid"/>
    <form:hidden path="categoryUuid" id="categoryUuid"/>
    <div class="modal-header">
        <button type="button" class="close"
                data-dismiss="modal" aria-hidden="true">
            &times;
        </button>
        <h4 class="modal-title" id="myModalLabel">
            案件分类
        </h4>
    </div>
    <div class="modal-body">
        <div class="form-group">
            <div class="col-sm-12">
                <select class="form-control categoryList">
                    <option value="">请选择案件分类</option>
                    <c:forEach items="${formDto.list}" var="item">
                        <option value="${item.uuid}">${item.name}</option>
                    </c:forEach>
                </select>
                <span class="error text-danger ErrorText"></span>
            </div>
        </div>
        <c:forEach items="${formDto.list}" var="item">
            <custom:case_category_list item="${item}"/>
        </c:forEach>
    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-primary" id="SubmitBtn">
            确定
        </button>
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭
        </button>
    </div>
</form:form>
<script type="text/javascript">
    $(".categoryList").change(function () {
        var value = $(this).val();
        $("#categoryUuid").val(value);
        $(this).parents(".form-group").nextAll().addClass("hide");
        if (value != '') {
            $(".form-group[parent=" + value + "]").removeClass("hide");
        }
    });

    $("#SubmitBtn").click(function () {
        var serialize = $("#changeCategoryForm").serialize();
        $.ajax({
            url: 'change_category_submit',
            data: serialize,
            type: 'post',
            cache: false,
            success: function (data) {
                if (!data.state) {
                    $(".ErrorText").html(data.msg);
                    return;
                }
                $(".category").html(data.msg)
                        .removeClass("label-default")
                        .addClass("label-primary");
                $('#myModal').modal('hide');
            },
            error: function () {
                alert("失败");
            }
        });
    });
</script>
</body>
</html>
